import os


class BisectConfig:
    """集中管理bisect模块的配置参数"""

    # 基础路径配置
    SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
    BISECT_RUN_SCRIPT = os.path.join(os.environ['LKP_SRC'], "programs/bisect-py/bisect_steps.py")
    BISECT_PERF_SCRIPT = os.path.join(os.environ['LKP_SRC'], "programs/bisect-py/bisect_perf_steps.py")
    BISECT_MIDPOINT_SCRIPT = os.path.join(os.environ['LKP_SRC'], "programs/bisect-py/bisect_midpoint_step.py")

    # 动态路径配置
    TEMP_RESULT_ROOT = None
    TEMP_GIT_BASE = None
    
    # 流程级重试配置
    PROCESS_MAX_RETRIES = 2           # 整个bisect流程最大重试次数
    PROCESS_RETRY_DELAY = 10          # 初始重试延迟(秒)
    
    # 操作级重试配置
    OPERATION_MAX_RETRIES = 3         # 单个操作(如作业提交)最大重试次数
    OPERATION_INITIAL_DELAY = 5       # 操作级初始重试延迟(秒)
    OPERATION_MAX_DELAY = 300         # 操作级最大重试延迟(秒)
    
    # 超时控制配置
    PERF_RANGE_JOB_TIMEOUT = 7200     # 性能基准作业超时(秒)
    JOB_POLL_TIMEOUT = 12600          # 作业轮询总超时(秒)
    JOB_NO_PROGRESS_TIMEOUT = 1800    # 作业无进展超时(秒)
    MAX_POLL_COUNT = 100              # 最大轮询次数

    # 复核验证配置
    ENABLE_RESULT_VERIFICATION = True     # 是否启用结果复核
    ENABLE_BOUNDARY_VERIFICATION = True   # 是否启用边界验证和HEAD检测
    PERF_VERIFICATION_SAMPLES = 3         # 性能测试复核时的采样次数
    FUNC_VERIFICATION_RUNS = 2            # 功能测试复核时的运行次数
    VERIFICATION_CONFIDENCE_LEVEL = 0.95  # 复核结果的置信水平
    VERIFICATION_TIMEOUT = 3600           # 边界验证超时时间(秒)
    SKIP_RESULT_MAX_CANDIDATES = 5        # Skip结果最多验证的候选数量

    # 任务复用配置
    JOB_REUSE_TIME_WINDOW_DAYS = 7        # 任务复用的时间窗口（天）

    # 其他配置
    CLEANUP_REGISTERED = False
    GIT_MIRROR_HOST = ""
    GIT_CLONE_RETRIES = 3
    GIT_CLONE_RETRY_DELAY = 30
    DB_QUERY_CACHE_TTL = 300
    REPO_VALIDATION_RETRIES = 2
    REPO_CLEANUP_ON_FAILURE = True
    LARGE_FILE_THRESHOLD = 10 * 1024 * 1024
    IMPORTANT_FILES = [
        'bisect.log',
        'bisect_process.log',
        'commit_jobs.jsonl',
        'error_log.jsonl',
        'structured_log.json'
    ]
